package company.pingan_F;

import java.util.*;

public class PingAn2 {
    public static void main(String[] args) {
        //排序结果
        Set<String> result = new TreeSet<>();
        int maxLength = 0;
        //遍历出一个字符串所有子串可能
        HashSet<String> dict = new HashSet<>();

        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        String[] s = str.split(" ");
        String str1 = s[0];
        String str2 = s[1];
        for (int i = 0, j = 1; i < str2.length(); i++, j = i + 1) {
            while (j <= str2.length()) {
                dict.add(str2.substring(i, j));
                j++;
            }
        }
        for (int i = 0, j = 1; i < str1.length(); i++, j = i + 1) {
            while (j <= str1.length()) {
                String tmp = str1.substring(i, j);
                if (j - i > maxLength && dict.contains(tmp)) {
                    maxLength = j - i;
                    result.clear();
                    result.add(tmp);
                } else if (j - i == maxLength && dict.contains(tmp)) {
                    result.add(tmp);
                }
                j++;
            }
        }
        for (String tmp : result) {
            System.out.println(tmp);
        }
    }
}
